package rpcSupport

import (
	"net"
	"net/rpc"
	"net/rpc/jsonrpc"
)

func ServerRpc(services ...interface{}) {

	rpc.Register(services)

	listener, err := net.Listen("tcp", ":1234")

	if err != nil {

		print(err)

	}

	for true {

		conn, err := listener.Accept()

		if err != nil {

			print(err)

		}

		go jsonrpc.ServeConn(conn)
	}
}

func NewClient(host string) (*rpc.Client, error) {

	conn, err := net.Dial("tcp", host)

	if err != nil {

		print(err)

	}

	if err != nil {

		return nil, err
	}

	client := jsonrpc.NewClient(conn)

	return client, nil
}
